const webpack = require('webpack');
const path = require('path');
const appData = require("./data.json");
const autumn = appData.autumn;

function resolve(dir) {
  return path.join(__dirname, dir)
}
const beauty = appData.beauty;

function resolve(dir) {
  return path.join(__dirname, dir)
};

module.exports = {
  chainWebpack(config) {
    config.resolve.alias
        .set('assets', resolve('src/assets'))
        .set('common', resolve('src/common'))
        .set('components', resolve('src/components'))
        .set('network', resolve('src/network'))
        .set('views', resolve('src/views'))
    config.plugin('context')
        .use(webpack.ContextReplacementPlugin,
            [/moment[/\\]locale$/, /zh-cn/])
  },
  devServer: {
    before(app) {
      app.get('/apis/autumn', function (req, res) {
        res.json({
          errno: 0,
          data: autumn
        });
      });
      app.get('/apis/beauty', function (req, res) {
        res.json({
          errno: 0,
          data: beauty
        });
      });
    }
  }
}